<template>
<div>
    <meta title="参数设置"></meta>
    <ManageTable border stripe :rowKey="tableData.rowKey" :columns="tableData.columns" :data="tableData.data" :btnGroup="tableData.btnGroup" :page="tableData.page">
    </ManageTable>
</div>
</template>

<script>
import then from "thenjs";
import moment from "moment";
import AppFrame from "../../../libs/app-frame";
import ManageTable from "../../../components/manage-table";
import PartnersSelect from '../../../components/partners-select';
export default {
    components: {
        ManageTable,
        PartnersSelect
    },
    data: function () {
        return {
            CurUserInfo: {},
            tableData: {
                rowKey: "RuleID",
                columns: [{
                        type: "selection",
                        width: 60,
                        align: "center",
                        able:'禁止删除',
                    },

                    {
                        title: "角色名称",
                        key: "RuleName",
                        width: 250,
                        filterKey: "RuleName",
                        filterType: "text"
                    },

                    {
                        title: "所属组织",
                        key: "iframe_orgstruct.OS_Name",
                        width: 250,
                        sortKey: "RuleOrgID",
                        sortable: "custom",
                        filterKey: "RuleOrgID",
                        filterType: "selectTree",
                        filterOptions: [],
                        filterMultiple: false
                    },

                    {
                        title: "描述",
                        key: "RuleInfo",
                        ellipsis: true
                    },

                    {
                        title: "操作",
                        key: "action",
                        width: 100,
                        align: "center",
                         able:'禁止修改',
                        render: (h, params) => {
                            return h("div", [
                                h(
                                    "Button", {
                                        props: {
                                            type: "primary",
                                            size: "small"
                                        },
                                        on: {
                                            click: () => {
                                                this.$router.push(
                                                    "/Manage/System/rule/Edit?RuleID=" + params.row.RuleID
                                                );
                                            }
                                        }
                                    },
                                    "编辑"
                                )
                            ]);
                        }
                    }
                ],
                data: [],
                btnGroup: [{
                    text: "删除所选",
                    type: "primary",
                    url: "/manage-api/system/rule/Del",
                    isShow: true,
                    icon: "trash-a",
                    loading: false,
                    able:'禁止删除',
                    actionText: "确定要删除所选吗?"
                }],
                page: {
                    total: 0,
                    current: 1,
                    pageSize: 20
                }
            },
            QueryModel: {
                Sort: null
            }
        };
    },
    created: function () {
        this.CurUserInfo = AppFrame.UserInfo.getUserInfo();
        this.setDefaultData();
        this.find();
    },
    watch: {
        $route: function () {
            //当路由改变时
            this.setDefaultData();
            this.find();
        }
    },
    methods: {
        setDefaultData: function () {
            this.tableData.page.current = Number(this.$route.query.CurPage) || 1;
            this.tableData.page.pageSize = Number(this.$route.query.PageSize) || 20;
            if (this.$route.query.PartnersID) {
                this.QueryModel.partnersId = Number(this.$route.query.PartnersID);
            }
        },

        find: function () {
            let self = this;
            let PostData = {};
            if (this.$route.query) PostData = this.$route.query;
            PostData.CurPage = this.tableData.page.current;
            PostData.PageSize = this.tableData.page.pageSize;
            then(function (defer) {
                    AppFrame.Http.Post("/manage-api/system/rule/getItems", PostData, defer);
                }).then(function (defer, Ret) {

                    if (Ret && Ret.Result == 1) {
                        self.tableData.page.total = Ret.Data.RsCount;
                        self.tableData.page.current = Ret.Data.CurPage;
                        self.tableData.page.pageSize = Ret.Data.PageSize;
                        //------------------
                        self.tableData.data.splice(0, self.tableData.data.length);
                        Ret.Data.DataList.forEach(function (item) {
                            self.tableData.data.push(item);
                        });

                        self.tableData.columns.forEach(function (col) {
                            if (col.key === "iframe_orgstruct.OS_Name") {
                                col.filterOptions.splice(0, col.filterOptions.length);
                                col.filterOptions = Ret.Data.OrgStruct;
                            }
                        });
                    } else {
                        defer({
                            msg: Ret.Msg
                        });
                    }
                })
                .fin(function (defer, err, ret) {
                    console.log(err);
                    self.$Message.error("操作错误,请重试");
                });
        }
    }
};
</script>

<style scoped>

</style>
